#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMessageBox>
#include <QTimer>
#include "misc.h"
#include "commclass.h"
#include "dialogselectport.h"
#include "commands.h"
#include "settings.h"
#include "status.h"

//! The time between each poll of the USB port in ms
#define TIMER_POLL_STATUS_INTERVAL  1

//! The interval between each PING is sent from both computer and SRI interface (in ms)
#define SRI_PING_INTERVAL     1000

//! SRI interface timeout limit (ms divided by SRI_PING_INTERVAL)
#define SRI_PING_TIMEOUT_LIMIT  5000/SRI_PING_INTERVAL

#define QLABEL_TX_STYLESHEET        "QLabel { background-color : red; border-style: outset;border-width: 1px;border-radius: 1px;border-color: black;}"
#define QLABEL_RX_STYLESHEET        "QLabel { background-color : green; border-style: outset;border-width: 1px;border-radius: 1px;border-color: black;}"
#define QLABEL_TXRXNONE_STYLESHEET  ""

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
  Q_OBJECT
public:
  explicit MainWindow(QWidget *parent = 0);
  ~MainWindow();
  DialogSelectPort *dlgSelectPort;
  CommClass *getSerialPtr();
  void updateUIfromSettings();
  void updateUIfromStatus();
  void showMessageBox(QString title, QString text, enum QMessageBox::Icon icon);
private:
  Ui::MainWindow *ui;
  CommClass *serialPort;
  QString currentSRIPort;
  void parseCommData(StructMessage message);
  QTimer *timerPollStatus;
  QTimer *timerPingPongEvent;
  Settings *settings;
  Status *status;
  quint16 lastPongCounter;
private slots:
  void actionPTTInputClicked();
  void actionPTTInputInvertClicked();
  void actionSerSRIPortTriggered();
  void on_actionConnect_triggered();
  void on_actionDisconnect_triggered();
  void timerPollStatusUpdate();
  void timerPingPongEventUpdate();
  void on_actionQuit_triggered();
  void on_actionTestButton_triggered();
  void on_pushButtonCATSettingsApply_clicked();
  void on_actionGetVersion_triggered();
  void on_comboBoxPTTOutputPhone_currentIndexChanged(int index);
  void on_comboBoxPTTOutputCW_currentIndexChanged(int index);
  void on_comboBoxPTTOutputDigital_currentIndexChanged(int index);
  void on_checkBoxPTTOutputInhibit_toggled(bool checked);
  void on_checkBoxPTTOutputAmpflier_toggled(bool checked);
  void on_spinBoxPTTRadioPreDelay_valueChanged(int arg1);
  void on_spinBoxPTTRadioPostDelay_valueChanged(int arg1);
  void on_spinBoxPTTAmplifierPreDelay_valueChanged(int arg1);
  void on_spinBoxPTTAmplifierPostDelay_valueChanged(int arg1);
  void on_spinBoxPTTInhibitPreDelay_valueChanged(int arg1);
  void on_spinBoxPTTInhibitPostDelay_valueChanged(int arg1);
  void on_spinBoxPTTAntennaPreDelay_valueChanged(int arg1);
  void on_spinBoxPTTAntennaPostDelay_valueChanged(int arg1);
  void on_actionSaveToEEPROM_triggered();

  void disconnectSerialPort();
  void msgBoxClosed(QAbstractButton* button);
  void on_comboBoxAudioRoutingScenario_currentIndexChanged(int index);
  void on_comboBoxAudioRoutingLineInCW_currentIndexChanged(int index);
  void on_comboBoxAudioRoutingLineInPhone_currentIndexChanged(int index);
  void on_comboBoxAudioRoutingLineInDigital_currentIndexChanged(int index);
  void on_comboBoxAudioRoutingMicPath_currentIndexChanged(int index);
  void on_checkBoxAudioRoutingMuteMic_clicked(bool checked);
  void on_checkBoxAudioRoutingPreamp_clicked(bool checked);
  void on_checkBoxAudioRoutingMuteLineOutPhone_clicked(bool checked);
  void on_checkBoxAudioRoutingMuteLineOutDigital_clicked(bool checked);
  void on_comboBoxAudioRoutingCompGeneratedPhone_currentIndexChanged(int index);
  void on_comboBoxAudioRoutingCompGeneratedDigital_currentIndexChanged(int index);
};

#endif // MAINWINDOW_H
